<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function breathe(amount) {
            return new Promise((resolve, reject) => {
                if (amount < 500) {
                    reject('That is too small of a value')
                }
                setTimeout(() => resolve(`Done for ${amount}`), amount)
            })
        }
        async function go(name, last) {
            console.log(name, last);
            const res = await breathe(1000);
            console.log(res);
            const res3 = await breathe(750);
            console.log(res3);
            const res2 = await breathe(300);
            console.log(res2);
            const res4 = await breathe(900);
            console.log(res4);
        }

        function catchErrors(fn) {
            // console.log(fn, '111');
            return function (...args) {
                return fn(...args).catch((err) => {
                    console.error(err);
                })
            }
        }
        const wrappedFunction = catchErrors(go);
        wrappedFunction('Wes', 'Bos')
        // breathe(600)
        //     .then(data => {
        //         console.log(data);
        //     })
        //     .catch(err => {
        //         console.log(err);
        //     })
    </script>
</body>

</html>